package com.lyz.dataStructure.LeetCode.dongtaiguihua;

/*
leetcode 数组区间 求和
 */
public class NumArray {

    private int[] sums;

    public  NumArray(int[] nums){
        sums = new int[nums.length+1];

        for(int i =0;i<nums.length;i++){
            sums[i+1] = sums[i] + nums[i];
        }
    }

    public  int sumRange(int i,int j){
        return  sums[j+1] - sums[i];
    }

    public static void main(String[] args) {
        int[] nums = {-2,0,3,-5,2,-1};
        NumArray numArray = new NumArray(nums);

        System.out.println(numArray.sumRange(2,5));
    }
}
